<template>
    <div style="width: 100%;">
        <el-select v-model="formdata.resultValue" placeholder="请选择" style="width: 100%" @change="handleChange">
            <el-option v-for="item in resultData" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
    </div>
</template>
  
<script setup>

import { onMounted, reactive, toRefs, watch } from "vue";

import {
    getWarehouseData,//仓库
} from "@/hooks"

const emits = defineEmits(['update:successAction'])

const props = defineProps({
    echoValue: {
        type: String,
        default: ""
    },
    types: {
        type: Number,
        default: 1
    }
})

watch(() => props.echoValue, (newVal) => {
    state.formdata.resultValue = newVal
})

const state = reactive({
    formdata: {
        resultValue: "",
    },
    resultData: [],
})

const { formdata, resultData } = toRefs(state)

const handleChange = (ev) => {
    console.log(ev,'666')
    emits('update:successAction', ev)
}

const typeFn = (data) => {
    data.forEach(o => {
        o.value = o.id
        o.label = o.name
    });
    return data
}

onMounted(async () => {
    let { types } = props
    // types 1 仓库
    if (types == 1) {
        let { returnData: getWarehouse } = getWarehouseData()
        let warehouse = await getWarehouse()
        state.resultData = typeFn(warehouse.data)
    }

})
</script>
  